import { menuItems } from '@/router/limitedRoutes';

//用于获取权限路由
export function getLimitedRoutes(allRoutes, user) {
  let routes = [];
  user = 'admin';
  if (allRoutes && allRoutes.length > 0) {
    routes = allRoutes.filter((r) => r.meta.users.indexOf(user) > -1);
    if (routes && routes.length > 0) {
      routes.forEach((rt) => {
        if (rt.children && rt.children.length > 0) {
          rt.children = getLimitedRoutes(rt.children, user);
        }
      });
    }
  }

  return routes;
}

//把路由转换为菜单
export function getDisplayMenus() {
  // console.log(routes);
  // let menus = [];
  // if (routes && routes.length > 0) {
  //     for (let index in routes) {
  //         if (routes[index].meta.show) {
  //             menus.push(routes[index])
  //         } else {
  //             menus.push(...routes[index].children)
  //         }
  //     }
  // }
  // return menus
  return menuItems;
}
